import request from "./request";
import {
  Register,
  Login,
  EmailLogin,
  CheckEmailCode,
  Reset,
} from "./loginTypes";
// 密码登录
const login = (query: Login) => {
  return request({
    url: "/login",
    method: "post",
    data: query,
  });
};

// 邮箱登录
const emailLogin = (query: EmailLogin) => {
  return request({
    url: "/emailLogin",
    method: "post",
    data: query,
  });
};

// 获取邮箱验证码
const getEmailCode = (query: { email: string; emailCode?: string }) => {
  return request({
    url: "/captchaEmail",
    method: "get",
    params: query,
  });
};

// 注册
const register = (query: Register) => {
  return request({
    url: "/register/email",
    method: "post",
    data: query,
  });
};
// 退出登录
const loginOut = () => {
  return request({
    url: "/logout",
    method: "post",
  });
};
// 获取用户信息
const getUserInfo = () => {
  return request({
    url: "/getInfo",
    method: "get",
  });
};

// 校验验证码
const checkEmail = (query: CheckEmailCode) => {
  return request({
    url: "/identityAuth",
    method: "post",
    data: query,
  });
};

// 重置密码
const resetPassword = (query: Reset) => {
  return request({
    url: "/resetPassword",
    method: "post",
    data: query,
  });
};

export {
  login,
  getEmailCode,
  emailLogin,
  register,
  loginOut,
  getUserInfo,
  checkEmail,
  resetPassword,
};
